//
//  LYViewController.m
//  LYPickerView
//
//  Created by liyang on 05/18/2018.
//  Copyright (c) 2018 liyang. All rights reserved.
//

#import "LYViewController.h"

#import <LYPickerView/LYPickerView.h>

@interface LYViewController ()

/// 静态选择器
@property (nonatomic, weak) LYStaticPicker *picker;

@end

@implementation LYViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    LYColumnStyle *left = [[LYColumnStyle alloc]init];
    left.selectedTextColor = [UIColor redColor];
    left.font = [UIFont systemFontOfSize:13];
    left.widthRatio = 0.25;
    left.textAlignment = NSTextAlignmentRight;
    
    LYColumnStyle *middle = [[LYColumnStyle alloc]init];
    middle.selectedTextColor = [UIColor greenColor];
    middle.widthRatio = 0.5;
    
    LYColumnStyle *right = [[LYColumnStyle alloc]init];
    right.selectedTextColor = [UIColor blackColor];
    right.widthRatio = 0.25;
    right.textAlignment = NSTextAlignmentLeft;
    
    CGFloat width = self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height;
    LYStaticPicker *picker = [[LYStaticPicker alloc]initWithFrame:(CGRect){10,50,width-20,height-100}];
    [picker setStyles:@[left, middle, right]];
    
    LYColumnData *leftData = [[LYColumnData alloc]init];
    NSMutableArray *temp1 = [NSMutableArray array];
    for (NSInteger i = 100; i > 70; i--)
    {
        [temp1 addObject:@(i)];
    }
    leftData.datas = temp1;
    [leftData setTransformBlock:^NSString *(NSNumber *value) {
        return [value.stringValue stringByAppendingString:@"strin"];
    }];
    
    LYColumnData *middleData = [[LYColumnData alloc]init];
    NSMutableArray *temp2 = [NSMutableArray array];
    for (NSInteger i = 0; i < 20; i++)
    {
        [temp2 addObject:@(i).stringValue];
    }
    middleData.datas = temp2;
    
    LYColumnData *rightData = [[LYColumnData alloc]init];
    rightData.datas = @[@"dog", @"cat", @"people"];
    
    [picker setDatas:@[leftData, middleData, rightData]];
    
    [picker setColumsSelectedValueDidChangeBlock:^(LYStaticPicker *view) {
        NSLog(@"%@", [view.datas valueForKeyPath:@"selectedValue"]);
    }];
    
    [picker setSelectedBackgroundColor:[UIColor yellowColor]];
    
    [self.view addSubview:picker];
    _picker = picker;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
